<?php
namespace Admin\Controller;
use Think\Controller;

class CommentlistController extends CommonController {
    public function index(){
    	$data = I('get.');
    	if(isset($data['bgtime'])){
    			
			if($data['issearch']=='1'){
				$_GET['p']=1;
				unset($_GET['issearch']);
    		}
    		/*if($data['issearch']=='1'){
    			$search = true;
    		}else{
    			$search = false;
    		}*/
            if($data['bgtime']==''){
                $data['btime']=strtotime('1971-01-01');
            }else{
                $data['btime']=strtotime($data['bgtime']);
            }
            if($data['endtime']==''){
                $data['etime']=time();
            }else{
                $data['etime']=strtotime($data['endtime']);
            }
    		$where['create_time'] = array('between', array($data['btime'], $data['etime']));
            $sql_all = "where t1.create_time between ".$data['btime'].' and '.$data['etime'];
    		
			if($data['content']!=''){
				$where['content'] = array('LIKE','%'.$data['content'].'%');
                $sql_all.=' and t1.content like "%'.$data['content'].'%" ';
			}
            $this->assign('content',$data['content']);
			$this->assign('bgtime',$data['bgtime']);
			$this->assign('endtime',$data['endtime']);
            $sql = "select t1.*,t2.title,t3.nickname from answer t1 left join question t2 on t1.qid=t2.qid left join user t3 on t1.uid=t3.uid ".$sql_all;
            $answer_search = M('answer')->query($sql);
			$count = count($answer_search);
            $this->page($count,$sql,$search);
    	}else{
            $sql = "select t1.*,t2.title,t3.nickname from answer t1 left join question t2 on t1.qid=t2.qid left join user t3 on t1.uid=t3.uid";
       		$answer_all=M('answer')->query($sql);
       		$count = count($answer_all);
            $this->page($count,$sql,false);
    	}

    	/*$answer = M('answer t1')->field('t1.*,t2.title,t3.nickname')->join('left join question t2 on t1.qid=t2.qid left join user t3 on t1.uid=t3.uid')->select();
    	$this->assign('answer',$answer);*/
    }

     public function page($count,$sql,$search=false){
        $Page = new \Think\Page($count,3);// 实例化分页类 
        // if($search){
        // 	$Page->firstRow='0';
        // }
        $sql_answer =$sql.' order by t1.create_time limit '.$Page->firstRow.','.$Page->listRows;
        $answer = M('auth_group_access')->query($sql_answer);
        /*var_dump($ques);*/
        /*$admin = M('auth_group_access t1')->join('left join auth_group t2 on t1.group_id=t2.id')->select(); */
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $this->assign('answer',$answer);
        $this->assign('count',$count);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
     }

     public function delAll(){
        $this->deleteAll('aid','answer');
    }

    public function del(){
        //var_dump(I('post.'));exit;
        $this->delOne('aid','answer');
    }
}

?>